Red Heart Campaign Database Visualization (Plots Only)

TW: This notebook contains discussion and media around topics such as domestic violence, sexual assault, physical violence, etc.

This notebook serves as a tool to visualize the data collected by the Red Heart Campaign. You can find the database here. The full process is detailed in this notebook here.

In [1]:
import plotly.express as px
import pandas as pd
import numpy as np
df = pd.read_csv("https://raw.githubusercontent.com/TangyKiwi/Worldie/master/RedHeart/redheart_data_cleaned.csv")

All Ages Bar Chart:

In [2]:
age = df.get("age")
age = list(map(int, age))

s = pd.DataFrame({"Age":age})["Age"].value_counts()
age_counts = pd.DataFrame({"Age":s.index, "Count":s.values})
fig = px.bar(age_counts, x="Age", y="Count", title="Age")
fig.show()

Age Group Bar Chart:

In [3]:
age_groups = pd.cut(age, bins=[-2, -1, 14, 24, 64, 100])
# (-2, -1] (-1, 14] (14, 24] (24, 64] (64, 100]
unique, counts = np.unique(age_groups, return_counts=True)
age_groups = dict(zip(unique, counts))
age_groups = pd.DataFrame({"Age Groups":["Unknown", "Children (0-14)", "Youth (15-24)", "Adults (25-64)", "Seniors (65+)"], "Count":age_groups.values()})
fig = px.bar(age_groups, x="Age Groups", y="Count", title="Age Groups")
fig.show()

Age Group Pie Chart:

In [4]:
fig = px.pie(age_groups, values="Count", names="Age Groups", title="Age Groups")
fig.show()

Context Bar Chart:

In [5]:
s = df["context"].value_counts()
context_counts = pd.DataFrame({"Context":s.index, "Count":s.values})
fig = px.bar(context_counts, x="Context", y="Count", title="Context")
fig.show()

Context Pie Chart:

In [6]:
fig = px.pie(context_counts, values="Count", names="Context", title="Context")
fig.show()

Cause Bar Chart:

Some cases have multiple causes, we process this by splitting through commas.

In [7]:
causes = []
for i in range(len(df["cause"])):
    for c in df["cause"][i].split(", "):
        causes.append(c.strip())

s = pd.DataFrame({"Cause":causes})["Cause"].value_counts()
cause_counts = pd.DataFrame({"Cause":s.index, "Count":s.values})
fig = px.bar(cause_counts, x="Cause", y="Count", title="Cause of Death")
fig.show()

Year Bar Chart:

In [8]:
year = df.get("year")
year = list(map(int, year))
s = pd.DataFrame({"Year":year})["Year"].value_counts()
year_counts = pd.DataFrame({"Year":s.index, "Count":s.values})
fig = px.bar(year_counts, x="Year", y="Count", title="Year")
fig.show()

Gender Bar Chart:

In [9]:
gender = df.get("gender")
s = pd.DataFrame({"Accused Gender":gender})["Accused Gender"].value_counts()
gender_counts = pd.DataFrame({"Accused Gender":s.index, "Count":s.values})
fig = px.bar(gender_counts, x="Accused Gender", y="Count", title="Accused Gender")
fig.show()

Gender Pie Chart:

In [10]:
fig = px.pie(gender_counts, values="Count", names="Accused Gender", title="Accused Gender")
fig.show()

More to come!